package homework;

import java.util.ArrayList;
import java.util.Iterator;

public class Homework02 {
    @SuppressWarnings({"all"})
    public static void main(String[] args) {
        ArrayList arrayList = new ArrayList();
        Car car1 = new Car("宝马","300000");
        Car car2 = new Car("奔驰","400000");
        arrayList.add(car1);
        arrayList.add(car2);
        System.out.println(arrayList);
        arrayList.remove(car1);
        System.out.println(arrayList);
        System.out.println(arrayList.contains(car1));//查找元素是否存在(F)
        System.out.println(arrayList.contains(car2));//T
        System.out.println(arrayList.size());
        System.out.println(arrayList.isEmpty());//F
        System.out.println(arrayList);

        for (Object o :arrayList ) {//增强for循环
            System.out.println(o);
        }

        System.out.println("==========");
        Iterator iterator = arrayList.iterator();
        while (iterator.hasNext()) {
            Object next =  iterator.next();
            System.out.println(next);

        }


    }
}
class Car{
    private String name;
    private String price;

    public Car(String name, String price) {
        this.name = name;
        this.price = price;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPrice() {
        return price;
    }

    public void setPrice(String price) {
        this.price = price;
    }

    @Override
    public String toString() {
        return "Car{" +
                "name='" + name + '\'' +
                ", price='" + price + '\'' +
                '}';
    }
}